import { ref } from "vue";
import { defineStore } from "pinia";
import { getTableData } from "@/api/system/positionManage";
import { getEmployeeIdAndName } from "@/utils/pengxi";
export const useInspectArea = defineStore("factory", () => {
  const inspectArea = ref();
  const inspectAreaOption = ref<any>([]);
  // 获取工厂下拉列表
  const getInspectAreaOption = async () => {
    if (inspectAreaOption.value.length === 0) {
      const data = await getTableData({});
      inspectAreaOption.value = data || [];
    }
  };
  return {
    inspectAreaOption,
    getInspectAreaOption,
    inspectArea,
    setInspectArea: val => {
      inspectArea.value = val;
    }
  };
});
export const usePrincipal = defineStore("principal", () => {
  const principal = ref();
  const principalList = ref<any>([]);
  // 获取用户列表
  const getPrincipalList = async () => {
    if (principalList.value.length === 0) {
      const data = await getEmployeeIdAndName();
      const newData = data || [];
      principalList.value = newData;
    }
  };
  return {
    principalList,
    getPrincipalList,
    principal,
    setPrincipal: val => {
      principal.value = val;
    }
  };
});

export const useTaskInfo = defineStore("taskInfo", () => {
  const taskInfo = ref();
  return {
    taskInfo,
    setTaskInfo: val => {
      taskInfo.value = val;
    }
  };
});
